package com.ztt.controller.admin;
import com.ztt.pojo.entity.zttSupplier;
import com.ztt.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class SupplierController {

    @Autowired
    private SupplierService supplierService;


    @GetMapping("/getAllSupplier")
    public List<zttSupplier> getAllSupplier(){
        return supplierService.selectAllSupplier();
    }

    @PostMapping("/insertSupplier")
    public String insertSupplier( @RequestBody zttSupplier supplier) {
        supplierService.insertSupplier(supplier);
        return "success";
    }


    @PostMapping("/getSupplierByID")
    public zttSupplier getSupplierByID(@RequestBody zttSupplier supplier) {
        return supplierService.getSupplierByID(supplier);
    }


    @PostMapping("/getSupplierByName")
    public zttSupplier getSupplierByName(@RequestBody zttSupplier supplier) {
        return supplierService.getSupplierByName(supplier);
    }


    @PostMapping("/updateSupplier")
    public String updateSupplier(@RequestBody zttSupplier supplier) {
        supplierService.updateSupplier(supplier);
        return "success";
    }


    @PostMapping("/deleteSupplier")
    public String deleteSupplier(@RequestBody zttSupplier supplier) {
        try{

            supplierService.deleteSupplier(supplier);
            return "success";
        }catch (Exception e){
            return "error";
        }
    }


}
